package com.airagg.annotation;

import com.google.gson.JsonElement;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Gson 日期序列化
 * Created by Administrator on 2017/4/4.
 */
public class GosnDateSerializer implements JsonSerializer<Date> {

    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    @Override
    public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
        String value = dateFormat.format(date);
        return jsonSerializationContext.serialize(value);
    }
}
